﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace POIParserConsole
{
    class Program
    {
        //The demo program to parse business name's inner structure
        //Currently, four tags are supported as follows:
        //BRD_ORG - the core terms of business name, such as brand name
        //LOC - represent where the business name is
        //ORG_MOD - the modifier terms in business name
        //ORG_MOD_LOC - the modifier terms related with location in business name
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("POIParserConsole.exe [Lexical Dictionary File Name] [CRF Model File Name] [POI Input File Name] [Parsed Output File Name]");
                return;
            }
            POIParser.POIParser parser = new POIParser.POIParser();
            parser.Initialize(args[0], args[1]);

            StreamReader sr = new StreamReader(args[2]);
            StreamWriter sw = new StreamWriter(args[3]);

            while (sr.EndOfStream == false)
            {
                string strLine = sr.ReadLine();
                List<POIParser.Token> tokenList = parser.Parse(strLine);

                StringBuilder sbOutput = new StringBuilder();
                foreach (POIParser.Token item in tokenList)
                {
                    sbOutput.Append(item.strTerm);
                    sbOutput.Append("[" + item.strTag + "] ");
                }

                sw.WriteLine(sbOutput.ToString().Trim());
            }
            sr.Close();
            sw.Close();
        }
    }
}
